from django.shortcuts import render
from django.views import View
from collections import OrderedDict
from goods.models import GoodsCategory, GoodsChannelGroup, GoodsChannel
from .utils import get_categories
from .models import ContentCategory,Content
# Create your views here.


class IndexValue(View):

    def get(self, requset):
        """提供首页广告页面"""
        # 准备商品分类对应的有序字典
        categories = get_categories()
        # 查询所有的广告类别, 顺序
        contents ={
            content_categories.key: content_categories.content_set.filter(status=True).order_by('sequence')
            for content_categories in ContentCategory.objects.all()
        }
        context = {
                'categories': categories,
                'contents':contents
        }
        return render(requset, 'index.html', context)
